package com.yhp.service.impl.userserviceimpl;

import com.yhp.bo.CenterUserBO;
import com.yhp.mapper.UsersMapper;
import com.yhp.mapper.centermapper.UsersMapperCustom;
import com.yhp.pojo.Users;
import com.yhp.service.userservice.CenterUserService;
import org.apache.catalina.User;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
public class CenterUserServiceImpl implements CenterUserService {

    @Autowired
    private UsersMapperCustom usersMapperCustom;
    @Autowired
    private UsersMapper usersMapper;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public Users queryUserInfo(String userId) {
        Users users1 = new Users();
        users1.setId(userId);
        Users users = usersMapper.selectOne(users1);
        users.setPassword(null);
        return users;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public Users updateUserInfo(String userId, CenterUserBO centerUserBO) {
        Users users = new Users();
        BeanUtils.copyProperties(centerUserBO,users);
        users.setId(userId);
        users.setUpdatedTime(new Date());
        System.out.println(users);
        usersMapperCustom.updateCenterUserInfo(users);

        return queryUserInfo(userId);
    }


    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public Users updateUserFace(String userId, String faceUrl) {
        Users users = new Users();
        users.setId(userId);
        users.setFace(faceUrl);
        users.setUpdatedTime(new Date());
        usersMapperCustom.updateFaceUrl(users);
        return queryUserInfo(userId);
    }
}
